using UnityEngine;

public class EnemyStats : CharacterStats
{
    private Enemy enemy;
    [Header("Level details")]
    [SerializeField] private int level = 1;
    [Range(0f, 1f)]
    [SerializeField] private float percantageModifier = 0.4f;
    private ItemDrop myDropSystem;
    public Stat soulsDropAmount;

    protected override void Awake()
    {
        soulsDropAmount.SetDefaultValue(100);
        ApplyLevelModifiers();
        base.Awake();
        enemy = GetComponent<Enemy>();
        myDropSystem = GetComponent<ItemDrop>();
    }

    private void ApplyLevelModifiers()
    {
        Modify(strength);
        Modify(agility);
        Modify(intelligence);
        Modify(vitality);
        Modify(damage);
        Modify(critChance);
        Modify(critPower);
        Modify(maxHp);
        Modify(armor);
        Modify(evasion);
        Modify(magicResistance);
        Modify(fireDamage);
        Modify(iceDamage);
        Modify(lightningDamage);
        Modify(soulsDropAmount);
    }

    private void Modify(Stat stat)
    {
        for (int i = 1; i < level; i++)
        {
            float modifier = stat.GetValue() * percantageModifier;
            stat.AddModifier(Mathf.RoundToInt(modifier));
        }
    }

    public override void TakeDamage(int damage)
    {
        base.TakeDamage(damage);
    }

    protected override void Die()
    {
        base.Die();
        enemy.Die();
        PlayerManager.Instance.currency += soulsDropAmount.GetValue();
        myDropSystem.GenerateDrop();
        Destroy(gameObject, 5f);
    }
}
